import { combineReducers } from "@reduxjs/toolkit";
import { createStore  } from "redux";
import { persistStore, persistReducer } from "redux-persist";
import storage from 'redux-persist/lib/storage'; // 默认使用 localStorage 作为存储介质
import app from "./modules/app/reducer";

// 合并
const reducer = combineReducers({
  app,
});

// 配置 redux-persist 的持久化选项
const persistConfig = {
  key: "system.redux.root", // 存储在 localStorage 中的键名
  storage, // 使用 localStorage 作为存储介质
  whitelist: ["app"], // 指定需要持久化的 reducer 键名
};

// 创建一个持久化的 reducer
const persistedReducer = persistReducer(persistConfig, reducer);
// 创建 Redux store
const store = createStore(persistedReducer);
// 创建持久化存储
const persistor = persistStore(store);

export { store, persistor };
